import { fileURLToPath, URL } from "node:url";

import { defineConfig, mergeConfig } from "vite";
import legacy from "@vitejs/plugin-legacy";
import vue2 from "@vitejs/plugin-vue2";
import vue2Jsx from "@vitejs/plugin-vue2-jsx";
import cdn from "vite-plugin-cdn-import";
import { defaultViteConfig } from "build/defineCondig.mjs";
// https://vitejs.dev/config/
export default mergeConfig(
  defaultViteConfig,
  defineConfig({
    plugins: [
      vue2(),
      vue2Jsx(),
      legacy({
        targets: ["chrome >= 49"],
        additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
      }),
      cdn({
        modules: [
          {
            name: "vue",
            var: "Vue",
            path: "https://cdn.bootcdn.net/ajax/libs/vue/2.7.16/vue.min.js",
          },
          {
            name: "vue-router",
            var: "VueRouter",
            path: "https://cdn.bootcdn.net/ajax/libs/vue-router/3.6.5/vue-router.js",
          },
          {
            name: "element-ui",
            var: "ELEMENT",
            path: "https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.14/index.js",
          },
        ],
      }),
    ],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    css: {
      preprocessorOptions: {
        sassOptions: { quietDeps: true },
      },
    },
  })
);
